<!--
 * @Description: 变更单提示
 * 
 * @Author: XiongYaoYuan<xiongyaoyuan>
 * @Date: 2023-08-02 14:39:15
 * @FilePath: /yuxiuproweb/src/views/mes/pro/workorder/mods/add/change.vue
-->
<template>
  <el-dialog
    :close-on-click-modal="false"
    v-dialogDrag
    title="变更单"
    :visible.sync="shows"
    width="600px"
    append-to-body
  >
    <div class="mb10">本次操作将生成以下变更单：</div>
    <el-table ref="multipleTable" :data="list">
      <el-table-column label="内容" align="center" prop="name" />
      <el-table-column label="位置" align="center" prop="address" />
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { listProOrder } from "@/api/asc/order";
export default {
  props: {
    show: Boolean,
    list: {
      type: Array,
      default: () => [],
    },
    data: {
      type: Object,
    },
  },
  data() {
    return {
      proOrderList: [],
    };
  },
  computed: {
    shows: {
      get() {
        return this.show;
      },
      set(newValue) {
        this.$emit("update:show", newValue);
      },
    },
  },
  created() {
    this.listProOrder();
  },
  methods: {
    // 获取变更单
    async listProOrder() {
      const { rows } = await listProOrder({
        orderId: this.data.orderId,
        state: "0",
      });
      this.proOrderList = rows || [];
    },
    // 保存
    submitForm() {
      if (this.data?.proOrderCustomCurtainId) {
        if (
          !!this.proOrderList.find(
		    (e) =>
		      e.customCurtainIds === `${this.data?.proOrderCustomCurtainId}`
		  )
		 
        ) {
          this.$message.error("当前商品存在变更单待落实1，请前往审核");
          return;
        }
      } else if (this.data?.orderCustomWindowCurtainId) {
        if (
          !!this.proOrderList.find(
            (e) =>
              e.customWindowCurtainIds ===
              `${this.data?.orderCustomWindowCurtainId}`
          )
        ) {
          this.$message.error("当前商品存在变更单待落实2，请前往审核");
          return;
        }
      } else if (this.data?.orderCustomOtherId) {
        if (
          !!this.proOrderList.find(
            (e) => e.customOtherIds === `${this.data?.orderCustomOtherId}`
          )
        ) {
          this.$message.error("当前商品存在变更单待落实3，请前往审核");
          return;
        }
      } else if (this.data?.orderRawId) {
        if (
          !!this.proOrderList.find(
            (e) => e.rawIds === `${this.data?.orderRawId}`
          )
        ) {
          this.$message.error("当前商品存在变更单待落实4，请前往审核");
          return;
        }
      }
      this.$emit("on-change", this.data);
      this.shows = false;
    },
  },
};
</script>
